#include<iostream>
#include<ctime>
#include<cstddef>
#include<cstring>
using namespace std;

void copy_with_pointers(const char* src,char* dst,size_t n)
{
    for(size_t i = 0 ; i < n ; i++)
    {
        *dst++ = *src++;
    }
}
void copy_with_indices(const char* src,char* dst, size_t n)
{
    for(size_t k = 0; k < n; ++k)
    {
        dst[k] = src[k];
    }
}
int main()
{
    int const n_bytes = 100000;
    int const n_calls = 1000;//Copy counts
    char* src = new char[n_bytes];
    char* dst = new char[n_bytes];
    
    memcpy(dst, src, n_bytes);
    clock_t start,end,reftime;
    
    //base
    start = clock();
    for( int k = 0; k != n_calls; ++k)
        memcpy(dst, src, n_bytes);
    end = clock();
    reftime = end - start;
    cout << "Wheng memcpy using time clocks:" << reftime << endl;
    
    start = clock();
    for( int k = 0; k != n_calls; ++k)
        copy_with_pointers(src, dst, n_bytes);
    end = clock();
    cout << "When point copy using time clocks:" << (end-start) << endl;
    cout << "With pointers: " << static_cast<double>(end-start)/reftime
         <<" times slower than memcpy.\n";
    
    

    start = clock();
    for( int k = 0; k != n_calls; ++k)
        copy_with_indices(src, dst, n_bytes);
    end = clock();
    cout << "When indices copy using time clocks:" << (end-start) << endl;
    cout << "With indices: " << static_cast<double>(end-start)/reftime
         <<" times slower than memcpy.\n";

    delete[] src;
    delete[] dst;
}
/******************************************
/*             Test Result
*******************************************/
///////////////////////////////////////////
//1.Visual C++ 2005
///////////////////////////////////////////

//cmd: cl 5.8.cpp /EHsc
//With pointers: 30 times slower than memcpy.
//With incides: 30 times slower than memcpy.

//
//cmd: cl 5.8.cpp /EHsc /O2
//
//Result:
//With pointers: 7 times slower than memcpy.
//With incides: 6 times slower than memcpy.


//
//cmd: cl 5.8.cpp /EHsc /Ox
//
//Result:
//With pointers: 3 times slower than memcpy.
//With incides: 3.5 times slower than memcpy.

///////////////////////////////////////////
//gcc 3.4.5
///////////////////////////////////////////
//g++ 5.8.cpp -o1
//g++ 5.8.cpp -o2
//g++ 5.8.cpp -o3


//With pointers: 1.#INF times slower than memcpy.
//With incides: 1.#INF times slower than memcpy.

//With pointers: 6.26667 times slower than memcpy.
//With incides: 5.2 times slower than memcpy.

//With pointers: Infinity times slower than memcpy.
//With incides: Infinity times slower than memcpy.
